<template>
  <!-- 审计屏蔽 新增 -->
  <div class="container-audit">
    <el-dialog
      :title="dialogConfig.name"
      :visible.sync="dialogVisible"
      @close="dialogVisible = false"
      append-to-body
    >
      <el-form ref="formRef" :model="formData" :rules="rules">
        <el-form-item label="包名" :label-width="'100px'" prop="uid">
          <el-input
            v-model="formData.packageName"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="渠道" :label-width="'100px'" prop="name">
          <el-input v-model="formData.channel" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="应用程序名称" :label-width="'100px'" prop="name">
          <el-input
            v-model="formData.applicationName"
            autocomplete="off"
          ></el-input>
        </el-form-item>

        <el-form-item
          label="起始版本号"
          :label-width="'100px'"
          prop="seqencing"
        >
          <el-input
            v-model="formData.startVersion"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="截至版本号"
          :label-width="'100px'"
          prop="seqencing"
        >
          <el-input v-model="formData.endVersion" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="设备系统" :label-width="'100px'" prop="link">
          <!-- <el-input v-model="formData.deviceType" autocomplete="off"></el-input> -->

          <el-select v-model="formData.deviceType" placeholder="请选择">
            <el-option
              v-for="item in deviceTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否启用" :label-width="'100px'" prop="link">
          <!-- <el-input v-model="formData.deleteFlag" autocomplete="off"></el-input> -->
          <el-select v-model="formData.deleteFlag" placeholder="请选择">
            <el-option
              v-for="item in deleteFlagOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { deepClone } from '@/utils'
import { auditAddApi, auditUpdateApi } from '@api/whisper'
export default {
  components: {},
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    value: {
      type: Object
    },
    request: {
      type: Object
    },
    dialogConfig: {
      type: Object
    }
  },
  data() {
    return {
      posting: false,
      formData: this.setup(this.value),
      rules: {},
      imageToView: null,
      imageDialogVis: false,
      deviceTypeOptions: [
        {
          value: 0,
          label: '安卓'
        },
        {
          value: 1,
          label: 'iOS'
        }
      ],
      deleteFlagOptions: [
        {
          value: 0,
          label: '启用'
        },
        {
          value: 1,
          label: '不启用'
        }
      ]
    }
  },
  created() {},
  mounted() {},
  methods: {
    setup() {
      if (!this.value) {
        return {
          id: 0,
          applicationName: '',
          channel: '',
          deviceType: 0,
          deleteFlag: 1,
          endVersion: '',
          packageName: '',
          startVersion: ''
        }
      } else {
        const clone = deepClone(this.value)
        return clone
      }
    },
    handleConfirm() {
      this.posting = true
      let func = null
      if (this.formData.id) {
        func = auditUpdateApi
      } else {
        func = auditAddApi
      }
      const clone = deepClone(this.formData)
      func(clone)
        .then(res => {
          this.dialogVisible = false
          this.$emit('success') // 刷新
        })
        .catch(err => {
          this.$message('error')
        })
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.formData = this.setup()
      }
    }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible')
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.container-audit {
}
</style>
